local skel = fk.CreateSkill{
  name = "emo__kuangcai",
}

Fk:loadTranslationTable{
  ["emo__kuangcai"] = "狂才",
  [":emo__kuangcai"] = "当你造成或受到伤害后，你可以将手牌摸至等同于你空置装备栏数张，弃置X张牌（X为你本回合发动此技能的次数）。",
  -- 若手牌数不小于自己的空置装备栏数，则不能发动〖狂才〗。

  ["#emo__kuangcai-ask"] = "狂才：你可以摸至%arg张，弃置%arg2张牌",

  ["$emo__kuangcai1"] = "满腹才学，可溢五车一石，可羞天下士人！",
  ["$emo__kuangcai2"] = "一身傲骨，可折不周之柱，可补支离之天！",
}

local spec = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      local num = #player:getAvailableEquipSlots() - #player:getCardIds("e")
      return player:getHandcardNum() < num
    end
  end,
  on_cost = function (self, event, target, player, data)
    local num = #player:getAvailableEquipSlots() - #player:getCardIds("e")
    local x = player:usedSkillTimes(skel.name) + 1
    if player.room:askToSkillInvoke(player, {
      skill_name = skel.name, prompt = "#emo__kuangcai-ask:::" .. num .. ":" .. x
    }) then
      return true
    end
  end,
  on_use = function(self, event, _, player, data)
    local room = player.room
    local num = #player:getAvailableEquipSlots() - #player:getCardIds("e")
    local draw = num - player:getHandcardNum()
    if draw < 1 then return end
    player:drawCards(draw, skel.name)
    if player.dead then return end
    local x = player:usedSkillTimes(skel.name)
    room:askToDiscard(player, {min_num = x, max_num = x, include_equip = true, skill_name = skel.name, cancelable = false})
  end,
}

skel:addEffect(fk.Damaged, spec)
skel:addEffect(fk.Damage, spec)

return skel
